🎖️GitЯра🎖️
Node / meshtastic / Meshtastic-Android / files / feature / widget / src / main / kotlin / org / meshtastic / feature / widget / AndroidAppWidgetUpdater.kt
Displaying Raw • Download
feature/widget/src/main/kotlin/org/meshtastic/feature/widget/AndroidAppWidgetUpdater.kt fix/qr-error-correction (7b45f84f) Text, 2.58 KB
T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.feature.widget
Tff7b72import T7ee787android.content.Context
Tff7b72import T7ee787androidx.glance.appwidget.GlanceAppWidgetManager
Tff7b72import T7ee787androidx.glance.appwidget.updateAll
Tff7b72import T7ee787co.touchlab.kermit.Logger
Tff7b72import T7ee787kotlinx.coroutines.CoroutineScope
Tff7b72import T7ee787kotlinx.coroutines.Dispatchers
Tff7b72import T7ee787kotlinx.coroutines.FlowPreview
Tff7b72import T7ee787kotlinx.coroutines.SupervisorJob
Tff7b72import T7ee787kotlinx.coroutines.flow.debounce
Tff7b72import T7ee787kotlinx.coroutines.flow.distinctUntilChanged
Tff7b72import T7ee787kotlinx.coroutines.launch
Tff7b72import T7ee787org.koin.core.annotation.Single
Tff7b72import T7ee787org.meshtastic.core.repository.AppWidgetUpdater
Tff7b72private Tff7b72const Tff7b72val Te6edf3WIDGET_UPDATE_DEBOUNCE_MS Tff7b72= T79c0ff5T79c0ff0T79c0ff0L
Tf0883e@Single
Tff7b72class T56d364AndroidAppWidgetUpdaterTb4b4b4(Tff7b72private Tff7b72val Te6edf3contextTb4b4b4: Te6edf3ContextTb4b4b4, Te6edf3stateProviderTb4b4b4: Te6edf3LocalStatsWidgetStateProviderTb4b4b4) Tb4b4b4:
Te6edf3AppWidgetUpdater Tb4b4b4{
Tff7b72private Tff7b72val Te6edf3scope Tff7b72= Te6edf3CoroutineScopeTb4b4b4(Te6edf3SupervisorJobTb4b4b4(Tb4b4b4) Tff7b72+ Te6edf3DispatchersTb4b4b4.Te6edf3DefaultTb4b4b4)
Tff7b72init Tb4b4b4{
T8b949e// Observe state changes and trigger a widget re-render whenever the data changes.
T8b949e// Glance compositions are ephemeral — the widget cannot self-update via collectAsState()
T8b949e// alone, so we must call updateAll() externally to drive re-renders.
Tf0883e@OptInTb4b4b4(Te6edf3FlowPreviewTff7b72::Te6edf3classTb4b4b4)
Te6edf3scopeTb4b4b4.Te6edf3launch Tb4b4b4{
Te6edf3stateProviderTb4b4b4.Te6edf3state
Tb4b4b4.Te6edf3debounceTb4b4b4(Te6edf3WIDGET_UPDATE_DEBOUNCE_MSTb4b4b4)
Tb4b4b4.Te6edf3distinctUntilChanged Tb4b4b4{ Te6edf3oldTb4b4b4, Te6edf3new Tff7b72-Tff7b72> Te6edf3oldTb4b4b4.Te6edf3copyTb4b4b4(Te6edf3updateTimeMillis Tff7b72= T79c0ff0Tb4b4b4) Tff7b72=Tff7b72= Te6edf3newTb4b4b4.Te6edf3copyTb4b4b4(Te6edf3updateTimeMillis Tff7b72= T79c0ff0Tb4b4b4) Tb4b4b4}
Tb4b4b4.Te6edf3collect Tb4b4b4{ Tff7b72if Tb4b4b4(Te6edf3hasWidgetInstancesTb4b4b4(Tb4b4b4)Tb4b4b4) Te6edf3updateAllTb4b4b4(Tb4b4b4) Tb4b4b4}
Tb4b4b4}
Tb4b4b4}
Tff7b72private Tff7b72suspend Tff7b72fun Td2a8ffhasWidgetInstancesTb4b4b4(Tb4b4b4)Tb4b4b4: Tffa657Boolean Tff7b72=
Te6edf3GlanceAppWidgetManagerTb4b4b4(Te6edf3contextTb4b4b4)Tb4b4b4.Te6edf3getGlanceIdsTb4b4b4(Te6edf3LocalStatsWidgetTff7b72::Te6edf3classTb4b4b4.Te6edf3javaTb4b4b4)Tb4b4b4.Te6edf3isNotEmptyTb4b4b4(Tb4b4b4)
Tff7b72override Tff7b72suspend Tff7b72fun Td2a8ffupdateAllTb4b4b4(Tb4b4b4) Tb4b4b4{
Tf0883e@SuppressTb4b4b4(Ta5d6ff"Ta5d6ffTooGenericExceptionCaughtTa5d6ff"Tb4b4b4)
Tff7b72try Tb4b4b4{
Te6edf3LocalStatsWidgetTb4b4b4(Tb4b4b4)Tb4b4b4.Te6edf3updateAllTb4b4b4(Te6edf3contextTb4b4b4)
Tb4b4b4} Tff7b72catch Tb4b4b4(Te6edf3eTb4b4b4: Te6edf3ExceptionTb4b4b4) Tb4b4b4{
Te6edf3LoggerTb4b4b4.Te6edf3eTb4b4b4(Te6edf3eTb4b4b4) Tb4b4b4{ Ta5d6ff"Ta5d6ffFailed to update widgetsTa5d6ff" Tb4b4b4}
Tb4b4b4}
Tb4b4b4}
Tb4b4b4}
Served by rngit 1.5.0 - Generated in 0.09s